package cn.tedu.boot21.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Controller
public class HelloController {
    //http://localhost:8080/hello
    // 当客户端向此地址发请求时下面的hello方法会执行
    @RequestMapping("/hello")
    public void hello( HttpServletRequest request, HttpServletResponse response) throws IOException {
        //获取客户端传过来的参数
        String info = request.getParameter("info");

        //设置相应类型 告诉客户端响应的内容为什么类型
        response.setContentType("text/html;charset=utf-8");
        //得到输出对象 异常抛出
        PrintWriter pw = response.getWriter();
        //输出数据
        pw.println("<h1>hello "+info+"</h1>");
        //关闭资源
        pw.close();
    }
}
